package com.alks.function.controller;

import com.alks.common.aop.ApiRestController;
import com.alks.common.aop.WebLogger;
import com.alks.entity.data.entity.PcMtlHueDesignRep;
import com.alks.entity.data.entity.SdMtlNew;
import com.alks.entity.data.entity.SdMtlTypeDetail;
import com.alks.entity.data.response.ResponseInfo;
import com.alks.function.data.dto.chengKong.assort.SdCustTypeDto;
import com.alks.function.data.dto.chengKong.assort.SdMtlTypeNewDto;
import com.alks.function.data.request.MaterialLotRequest;
import com.alks.function.data.request.MaterialOutRequest;
import com.alks.function.data.request.MaterialRequest;
import com.alks.function.data.request.last.OutsoleOrderDetailReq;
import com.alks.function.data.request.operate.material.GeneralMaterialRequest;
import com.alks.function.data.request.operate.material.MaterialDetail1Request;
import com.alks.function.data.request.order.PcOrderMtlRegularSingleRequest;
import com.alks.function.data.request.stock.*;
import com.alks.function.service.MaterialService;
import com.google.zxing.WriterException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@ApiRestController("/material")
@Slf4j
@Api(tags = {"材料出/入库查询",
        "开发部-开发作业-材料订购作业",
        "开发部-开发作业-通用订购作业",
        "开发部-开发作业-大底订购作业",
        "开发-物料颜色定义",
        "开发-材料属性定义",
        "开发-材料建档"})
public class MaterialController {

    @Autowired
    private MaterialService materialService;

    @WebLogger
    @ApiOperation(value = "入库明细查询",tags = "材料出/入库查询")
    @PostMapping("/getInventoryDetail")
    public ResponseInfo getInventoryDetail(@RequestBody MaterialRequest request){
        return materialService.getInventoryDetail(request);
    }

    @WebLogger
    @PostMapping("/getLotDetail")
    @ApiOperation(value = "材料入库指令明细",tags = "材料出/入库查询")
    public ResponseInfo getLotDetail(@RequestBody MaterialLotRequest request){
        return materialService.getLotDetailInfo(request);
    }

    @WebLogger
    @PostMapping("/exportMaterial")
    @ApiOperation(value = "材料入库导出",tags = "材料出/入库查询")
    public void exportMaterial(HttpServletResponse response,@RequestBody MaterialRequest request){
        materialService.exportMaterial(request,response);
    }

    @WebLogger
    @PostMapping("/getMaterialDetailOut")
    @ApiOperation(value = "材料出库领料明细",tags = "材料出/入库查询")
    public ResponseInfo getMaterialDetailOut(@RequestBody MaterialOutRequest request){
        return materialService.getMaterialDetailOut(request);
    }

    @WebLogger
    @PostMapping("/exportMaterialDetailOut")
    @ApiOperation(value = "材料出库领料导出",tags = "材料出/入库查询")
    public void exportMaterialDetailOut(@RequestBody MaterialOutRequest request,HttpServletResponse response){
        materialService.exportMaterialDetailOut(request,response);
    }

    @WebLogger
    @PostMapping("/getSendOutList")
    @ApiOperation(value = "材料出库实发明细",tags = "材料出/入库查询")
    public ResponseInfo getSendOutList(@RequestBody MaterialLotRequest request){
        return materialService.getSendOutList(request);
    }

    @WebLogger
    @PostMapping("/pcOrderMtlRS")
    @ApiOperation(value = "选订单材料正单",tags = "开发部-开发作业-材料订购作业")
    public ResponseInfo pcOrderMtlRS(@RequestBody PcOrderMtlRegularSingleRequest request){
        return materialService.pcOrderMtlRS(request);
    }

    @WebLogger
    @PostMapping("/pcOrderMtlSo")
    @ApiOperation(value = "选订单材料补单",tags = "开发部-开发作业-材料订购作业")
    public ResponseInfo pcOrderMtlSo(@RequestBody PcOrderMtlRegularSingleRequest request){
        return materialService.pcOrderMtlSo(request);
    }

    //生成订购资料
    @WebLogger
    @PostMapping("/pcOrderMtlMakeOrder")
    @ApiOperation(value = "生成订购资料",tags = "开发部-开发作业-材料订购作业")
    public ResponseInfo pcOrderMtlMakeOrder(@RequestBody PcOrderMtlRegularSingleOutRequest request){
        return materialService.pcOrderMtlMakeOrder(request);
    }
    // 查询本人的材料订购明细

    @WebLogger
    @PostMapping("/pcOrderMtlMakeOrderDetail")
    @ApiOperation(value = "材料订购明细",tags = "开发部-开发作业-材料订购作业")
    public ResponseInfo pcOrderMtlMakeOrderDetail(@RequestBody PcOrderMaterialOrderDetailRequest request){
        return materialService.pcOrderMtlMakeOrderDetail(request);
    }

    //形成订购单号
    @WebLogger
    @PostMapping("/createPcOrderMtlOrder")
    @ApiOperation(value = "形成订购订单号",tags = "开发部-开发作业-材料订购作业")
    public ResponseInfo createPcOrderMtlOrder(@RequestBody PcOrderMtlOrderCreateRequest request){
        return materialService.createPcOrderMtlOrder(request);
    }

    //通用订购作业

    @WebLogger
    @GetMapping("/downUniversalExcel")
    @ApiOperation(value = "导出订购单",tags = "开发部-开发作业-通用订购作业")
    public void downUniversalExcel(@RequestParam String slipNo,HttpServletResponse response) throws IOException, WriterException {
         materialService.downUniversalExcel(slipNo,response);
    }

    @WebLogger
    @PostMapping("/mtl/getMaterialADetail1")
    @ApiOperation(value = "通用材料订购明细",tags = "开发部-开发作业-通用订购作业")
    public ResponseInfo getMaterialADetail1(@RequestBody MaterialDetail1Request request){
        return materialService.getMaterialADetail1(request);
    }

    //分类辅助生成/置空物料编码/生成物料编码
    @WebLogger
    @PostMapping("/mtl/updateMaterialADetail1")
    @ApiOperation(value = "删除修改接口汇总",tags = "开发部-开发作业-通用订购作业")
    public ResponseInfo updateMaterialADetail1(@RequestBody GeneralMaterialRequest request){
        return materialService.updateMaterialADetail1(request);
    }

    //导出订购单
    @WebLogger
    @ApiOperation(value = "导出订购单",tags = "开发部-开发作业-材料订购作业")
    @GetMapping("/downMtlPurSlipExcel")
    public void downMtlPurSlipExcel(@RequestParam String slipNo,HttpServletResponse response) throws IOException, WriterException {
         materialService.downMtlPurSlipExcel(slipNo,response);
    }

    //大底订购作业 选指令 正单：1，补单：2  生成订单材料的时候 添加数据到pc_mtl_pre_other
    @WebLogger
    @PostMapping("/mold/getPcMtlMoldLot")
    @ApiOperation(value = "选指令",tags = "开发部-开发作业-大底订购作业")
    public ResponseInfo getPcMtlMoldLot(@RequestBody PcMtlMoldLotRequest request){
        return materialService.getPcMtlMoldLot(request);
    }

    //生成订购资料
    @WebLogger
    @PostMapping("/mold/createPcMtlMoldLot")
    @ApiOperation(value = "生成订购资料",tags = "开发部-开发作业-大底订购作业")
    public ResponseInfo createPcMtlMoldLot(@RequestBody CreateMtlMoldRequest request){
        return materialService.createPcMtlMoldLot(request);
    }

    //大底订购明细
    @WebLogger
    @PostMapping("/mold/getOutsoleOrderDetail")
    @ApiOperation(value = "大底订购明细",tags = "开发部-开发作业-大底订购作业")
    public ResponseInfo getOutsoleOrderDetail(@RequestBody OutsoleOrderDetailReq request){
        return materialService.getOutsoleOrderDetail(request);
    }

    @GetMapping("/downloadSoleOrder")
    @WebLogger
    @ApiOperation(value = "导出订购单",tags = "开发部-开发作业-大底订购作业")
    public void downloadSoleOrder(HttpServletResponse response,@RequestParam String slipNo) throws IOException, WriterException {
        materialService.downloadSoleOrder(response,slipNo);
    }

    //1插入材料信息先通过选择物料编码 物料编码查询 固定携带L501000 参数 选择完可插入信息进行数据插入
    @WebLogger
    @PostMapping("/mold/insertIntoOther")
    @ApiOperation(value = "插入材料信息",tags = "开发部-开发作业-大底订购作业")
    public ResponseInfo insertIntoOther(@RequestBody IMaterialIMReq request){
        return materialService.insertIntoOther(request);
    }

    //生成物料编码 //置空物料编码 //形成订购单 //置空订购信息 //复制材料信息 //修改材料信息  //打勾记录删除
    @WebLogger
    @PostMapping("/mold/operateSole")
    @ApiOperation(value = "生成置空等",tags = "开发部-开发作业-大底订购作业")
    public ResponseInfo operateSole(@RequestBody PcSoleOperateReq request){
        return materialService.operateSole(request);
    }

    //物料色系定义
    @GetMapping("/mtl/color/mtlHueDesign")
    @WebLogger
    @ApiOperation(value = "色系定义查询",tags = "开发-物料颜色定义")
    public ResponseInfo mtlHueDesign(@RequestParam(required = false) @ApiParam(value = "当choose参数为2的时候携带 为1不需要携带 分页也只有choose为2需要携带") String colorName,
                                     @RequestParam @ApiParam(value = "1:色系定义查询 2：颜色定义查询") String choose,
                                     @RequestParam(required = false) Integer pageNum,
                                     @RequestParam(required = false) Integer pageSize){
        return materialService.mtlHueDesign(choose,colorName,pageNum,pageSize);
    }

    //添加色系定义 添加颜色定义 修改色系定义 修改颜色定义 删除色系定义 删除颜色定义
    @ApiOperation(value = "删除添加修改",tags = "开发-物料颜色定义")
    @PostMapping("/mtl/color/updateHueDesign")
    @WebLogger
    public ResponseInfo updateHueDesign(@RequestBody PcMtlHueDesignRep rep,
                                        @RequestParam @ApiParam(value = "1:添加色系定义 2:添加颜色定义 3:修改色系定义 4: 修改颜色定义 5:删除色系定义 6:删除颜色定义") String choose,
                                        @RequestParam(required = false) @ApiParam(value = "操作颜色定义的时候携带") String colorName){
        return materialService.updateHueDesign(rep,choose,colorName);
    }

    @GetMapping("/mtl/property/mtlPropertyListTree")
    @WebLogger
    @ApiOperation(value = "材料属性定义",tags = "开发-材料属性定义")
    public ResponseInfo mtlPropertyListTree(){
        return materialService.mtlPropertyListTree();
    }

    @PostMapping("/mtl/property/insertSdMtlTypeNew")
    @WebLogger
    @ApiOperation(value = "添加材料分类",tags = "开发-材料属性定义")
    public ResponseInfo insertSdMtlTypeNew(@RequestBody @ApiParam(value = "当前行的数据") SdMtlTypeNewDto req,
                                           @RequestParam @ApiParam(value = "分类编码 前端强制 当前分类的分类编码 + 随机数字或单词尽量为两位") String typeNo,
                                           @RequestParam String typeName){
        return materialService.insertSdMtlTypeNew(req,typeNo,typeName);
    }

    //删除 当前列不含有子项
    @PostMapping("/mtl/property/deleteSdMtlTypeNew")
    @WebLogger
    @ApiOperation(value = "删除材料分类",tags = "开发-材料属性定义")
    public ResponseInfo deleteSdMtlTypeNew(@RequestBody SdMtlTypeNewDto req){
        return materialService.deleteSdMtlTypeNew(req);
    }

    //修改
    @PostMapping("/mtl/property/updateSdMtlTypeNew")
    @WebLogger
    @ApiOperation(value = "修改材料分类",tags = "开发-材料属性定义")
    public ResponseInfo updateSdMtlTypeNew(@RequestBody @ApiParam(value = "传入通用 也就是remark 主辅料只有第二级需要传也就是 mtlProperty") SdMtlTypeNewDto req){
        return materialService.updateSdMtlTypeNew(req);
    }

    //材料属性查询
    @PostMapping("/mtl/property/sdMtlTypeDetailList")
    @WebLogger
    @ApiOperation(value = "材料属性查询",tags = "开发-材料属性定义")
    public ResponseInfo sdMtlTypeDetailList(@RequestBody @ApiParam(value = "材料属性 大中小名称和编码都必须要携带") SdMtlTypeDetail req){
        return materialService.sdMtlTypeDetailList(req);
    }

    //新增材料属性 SdMtlTypeDetail

    @WebLogger
    @PostMapping("/mtl/property/insertSdMtlTypeDetail")
    @ApiOperation(value = "材料属性添加",tags = "开发-材料属性定义")
    public ResponseInfo insertSdMtlTypeDetail(@RequestBody @ApiParam(value = "材料属性的序号也需要填充进req") SdMtlTypeDetail req){
        return materialService.insertSdMtlTypeDetail(req);
    }

    //宽幅定义 单位定义 贴合加工方式定义返回
    @GetMapping("/mtl/property/mtlPropertyList")
    @WebLogger
    @ApiOperation(value = "材料属性properties 宽幅 spec、单位 unit、贴合加工 prdType",tags = "开发-材料属性定义")
    public ResponseInfo mtlPropertyList(){
        return materialService.mtlPropertyList();
    }

    //材料属性定义
    @GetMapping("/mtl/property/mtlPropertyRD")
    @WebLogger
    @ApiOperation(value = "材料属性关联表格",tags = "开发-材料属性定义")
    public ResponseInfo mtlPropertyRD(@RequestParam @ApiParam(value = "材料属性定义当中的材料属性") String typeName){
        return materialService.mtlPropertyRD(typeName);
    }

    @WebLogger
    @PutMapping("/mtl/property/insertProperty")
    @ApiOperation(value = "材料属性添加 宽幅添加、单位定义添加、贴合添加",tags = "开发-材料属性定义")
    public ResponseInfo insertProperty(@RequestParam String code,
                                       @RequestParam String name,
                                       @RequestParam(required = false) @ApiParam(value = "只有添加宽幅定义的时候携带也就是序号") String seqNo,
                                       @RequestParam @ApiParam(value = "1:材料属性定义 2：宽幅定义 3：单位定义 4：贴合加工方式定义") String choose){
        return materialService.insertProperty(code,name,seqNo,choose);
    }

    @WebLogger
    @ApiOperation(value = "材料属性关联规格添加",tags = "开发-材料属性定义")
    @PostMapping("/mtl/property/insertPropertyDetail")
    public ResponseInfo insertPropertyDetail(@RequestParam @ApiParam(value = "材料属性定义材料") String mtlName,
                                             @RequestParam @ApiParam(value = "材料属性关联规格编码 编码不能大于100") String seqNo,
                                             @RequestParam @ApiParam(value = "材料属性关联规格") String spec){
        return materialService.insertPropertyDetail(mtlName,seqNo,spec);
    }

    //SdCustTypeDto
    @WebLogger
    @ApiOperation(value = "客户分类",tags = "开发-材料属性定义")
    @GetMapping("/mtl/property/sdCustTypeAVen")
    public ResponseInfo sdCustTypeAVen(@RequestParam @ApiParam(value = "1：客户分类 2：厂商分类") String choose){
        return materialService.sdCustTypeAVen(choose);
    }

    @WebLogger
    @ApiOperation(value = "添加客户分类、厂商分类",tags = "开发-材料属性定义")
    @PostMapping("/mtl/property/insertSdCustType")
    public ResponseInfo insertSdCustType(@RequestBody SdCustTypeDto req,
                                         @RequestParam String parentLevel,
                                         @RequestParam @ApiParam(value = "1：客户分类 2：厂商分类") String choose){
        return materialService.insertSdCustType(req,parentLevel,choose);
    }

    @WebLogger
    @ApiOperation(value = "删除客户分类、厂商分类",tags = "开发-材料属性定义")
    @PostMapping("/mtl/property/deleteSdCustOrVen")
    public ResponseInfo deleteSdCustOrVen(@RequestBody @ApiParam("如果当前分类下含有数据前端强制不允许删除") SdCustTypeDto req,
                                          @RequestParam @ApiParam(value = "1：客户分类 2：厂商分类") String choose){
        return materialService.deleteSdCustOrVen(req,choose);
    }
    //材料建档查询 SdMtlNew SdMtlNewReq

    @WebLogger
    @PostMapping("/mtl/sdMtlNewList")
    @ApiOperation(value = "材料查询",tags = "开发-材料建档")
    public ResponseInfo sdMtlNewList(@RequestBody SdMtlNewReq req){
        return materialService.sdMtlNewList(req);
    }

    @WebLogger
    @PostMapping("/mtl/downloadSdMtlNew")
    @ApiOperation(value = "材料导出",tags = "开发-材料建档")
    public void downloadSdMtlNew(HttpServletResponse response,@RequestBody SdMtlNewReq req) throws IOException {
        materialService.downloadSdMtlNew(response,req);
    }
    //组成材料
    @WebLogger
    @PostMapping("/mtl/createSdMtlNew")
    @ApiOperation(value = "组成、插入材料",tags = "开发-材料建档")
    public ResponseInfo createSdMtlNew(@RequestBody SdMtlNew req
                                        ,@RequestParam @ApiParam(value = "1：组成材料 2：插入材料 3：修改") String choose) {
        return materialService.createSdMtlNew(req, choose);
    }
}
